home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / shape.lha / shape / line.h < prev    next >
Text File  |  1993-08-08  |  1KB  |  60 lines

  1. ifndef LINE_H
  2. define LINE_H
  3.  
  4. lass line : public shape
  5.  
  6. *
  7.    line from "w" to "e"
  8.  
  9.    north() is defined as `above the middle as
  10.    far north as the northernmost point'
  11.  
  12.    nw ---- n ---- ne    nw ---- n ---- ne
  13.    |            *  |    |  *            |
  14.    |         *     |    |    *          |
  15.    w       m       e    w       m       e
  16.    |    *          |    |         *     |
  17.    | *             |    |            *  |
  18.    sw ---- s ---- se    sw ---- s ---- se
  19. /
  20.    point w, e;
  21.  
  22. ublic:
  23.    point north() { return point((w.x+e.x)/2, e.y<w.y?w.y:e.y); }
  24.    point neast() { return point(e.x, e.y<w.y?w.y:e.y); }
  25.    point east()  { return point(e.x, (w.y+e.y)/2); }
  26.    point seast() { return point(e.x, e.y<w.y?e.y:w.y); }
  27.    point south() { return point((w.x+e.x)/2, e.y<w.y?e.y:w.y); }
  28.    point swest() { return point(w.x, e.y<w.y?e.y:w.y); }
  29.    point west()  { return point(w.x, (w.y+e.y)/2); }
  30.    point nwest() { return point(w.x,  e.y<w.y?w.y:e.y); }
  31.    point middle() { return point((w.x+e.x)/2, (w.y+e.y)/2); }
  32.  
  33.    void move(int a, int b)
  34.    { w.x += a; w.y += b; e.x += a; e.y += b; }
  35.    void draw() { put_line(w, e); }
  36.  
  37.    line(point a, point b)
  38.    {
  39. if (a.x < b.x) {
  40.     w = a;
  41.     e = b;
  42. } else {
  43.     w = b;
  44.     e = a;
  45. }
  46.    }
  47.  
  48.    line(point a, int len)
  49.    {
  50. if (len >= 0) {
  51.     w = point(a.x+len-1,a.y);
  52.     e = a;
  53. } else {
  54.     w = a;
  55.     e = point(a.x+len-1,a.y);
  56. }
  57.    }
  58. ;
  59. endif
  60.